<%@page import="org.jeecgframework.web.util.StaticValue"%>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
 <head>
  <title>联系表</title>
  <t:base type="jquery,easyui,tools,DatePicker"></t:base>
  <script type="text/javascript" src="plug-in/ckfinder/ckfinder.js"></script>
<script type="text/javascript">
function checkTpHeaderUnique(){
	var type = $("#type").val();
	var belongOrg = $("#belongOrg").val();//机构
	var position = $("#position").val();//职位
	var conBusiness = $("input[name='conBusiness']:checked").val();//业务
	var state = $("#state").val();//状态
	var flag = true;
	if(type === '<%=StaticValue.DIC_CONTACT_TYPE_TP_CONTACT%>' &&
			position === '<%=StaticValue.DIC_CONTACT_POSITION_TP_SERVER_BUSINESSR%>' && 
				(conBusiness != undefined && conBusiness.indexOf('<%=StaticValue.DIC_BUS_SCOPE_INSPECTION%>') >= 0) && 
					state === '<%=StaticValue.DIC_ENGINEER_STATE_ONJOB%>'){
		$.ajax({
			url : "zyContactsController.do?checkTpIpHeaderUnique",
			data : {
				"belongOrg" : belongOrg,
				"type" : "add"
				},
			cache : false,
			dataType : 'json',
			async : false,
			type : 'POST',
			success : function(data){
				if(!data.success){
					tip(data.msg);
				}
				flag = data.success;
			}
		});
	}
	var belongCinema = $("#belongCinema").val();
	if(flag){//检查 影院 巡检 联系人 唯一性
		if(type === '<%=StaticValue.DIC_CONTACT_TYPE_CINEMA_CONTACT%>' &&
				position === '<%=StaticValue.DIC_CONTACT_POSITION_C_MANAGER%>' && 
					(conBusiness != undefined &&conBusiness.indexOf('<%=StaticValue.DIC_BUS_SCOPE_INSPECTION%>') >= 0) && 
						state === '<%=StaticValue.DIC_ENGINEER_STATE_ONJOB%>'){
			$.ajax({
				url : "zyContactsController.do?checkCmIpHeaderUnique",
				data : {
					"belongCinema" : belongCinema
					},
				cache : false,
				dataType : 'json',
				async : false,
				type : 'POST',
				success : function(data){
					if(!data.success){
						tip(data.msg);
					}
					flag = data.success;
				}
			});
		}
	}
	var cellphone1 = $("#cellphone1").val();
	var cellphone2 = $("#cellphone2").val();
	if(flag){//通过第一个验证 才可以进行第二个验证
		var name = $("#name").val();
		if(name !== '' && cellphone1 !== ''){
			$.ajax({
				url : "zyContactsController.do?checkCtUnique",
				data : {
					"type" : "add",
					"name" : name,
					"cellphone1" : cellphone1
					},
				cache : false,
				dataType : 'json',
				async : false,
				type : 'POST',
				success : function(data){
					if(!data.success){
						tip(data.msg);
					}
					flag = data.success;
				}
			});
		}
	}
	if(flag){
		var baseId = $("#sysUserId").val();
		if(baseId !== ''){
			$.ajax({
				url : "zyContactsController.do?checkLinkSysUserUnique",
				data : {
					"baseId" : baseId
					},
				cache : false,
				dataType : 'json',
				async : false,
				type : 'POST',
				success : function(data){
					if(!data.success){
						tip(data.msg);
					}
					flag = data.success;
				}
			});
		}
	}
	if(flag){
		if(cellphone1 !== '' && cellphone2 !== '' && cellphone1 == cellphone2){
			tip("手机1和手机2不能相同");
			flag = false;
		}
	}
	return flag;
}
  
  </script>
 </head>
 <body>
  <t:formvalid formid="formobj" dialog="true" usePlugin="password" layout="table" action="zyContactsController.do?doAdd" tiptype="3" beforeSubmit="checkTpHeaderUnique">
					<input id="id" name="id" type="hidden" value="${zyContactsPage.id }">
		<table cellpadding="0" cellspacing="1" class="formtable">
				<tr>
					<td align="right">
						<label class="Validform_label">
							系统用户:
						</label>
					</td>
					<td class="value">
					     	<input name="tsBaseUser.id" type="hidden" id="sysUserId" />
			                <input name="realName" class="inputxt" id="realName" readonly="readonly" />
			                <t:choose hiddenName="sysUserId" hiddenid="id" url="zyContactsController.do?zySysUsers" name="sysUserList"
			                          icon="icon-search" title="系统用户列表" textname="realName" isclear="true" />
							<span class="Validform_checktip"></span>
							<label class="Validform_label" style="display: none;">系统用户</label>
					</td>
					<td align="right">
						<label class="Validform_label">
							类型:
						</label>
					</td>
					<td class="value">
							<select name="type" id="type" onchange="changeType()" >
						        <option id='cinema_contact' value="<%=StaticValue.DIC_CONTACT_TYPE_CINEMA_CONTACT %>">影院联系人</option>   
						        <option id='tp_contact' value="<%=StaticValue.DIC_CONTACT_TYPE_TP_CONTACT %>">第三方联系人</option>
					      	</select>
							<span class="Validform_checktip"></span>
							<label class="Validform_label" style="display: none;">类型</label>
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							所属机构或影院:
						</label>
					</td>
					<td class="value" id="cinema">
							<input name="belongCinema.id"  type="hidden" id="belongCinema">
			                <input name="cinemaName" class="inputxt" id="cinemaName" readonly="readonly" datatype="*" nullmsg="请选择所属影院" style="width:260px;"/>
			                <t:choose hiddenName="belongCinema" hiddenid="id" url="zyCinemaController.do?zyChooseCmOfContact" name="cinemaList"
			                          icon="icon-search" title="影院列表" textname="name" inputTextname="cinemaName"  isclear="true"></t:choose>
					</td>
					<td class="value" id="org" style="display: none;">
							<input name="belongOrg.id" type="hidden" id="belongOrg">
			                <input name="shortname" class="inputxt" id="shortname" readonly="readonly"  nullmsg="请选择所属机构" style="width:260px;"/>
			                <t:choose hiddenName="belongOrg" hiddenid="id" url="zyContactsController.do?zyOrgs" name="orgList"
			                          icon="icon-search" title="机构列表" textname="shortname" isclear="true"></t:choose>
					</td>
					<td align="right" style="width: 100px;">
						<label class="Validform_label">名字:</label>
					</td>
					<td class="value" style="width: 300px;">
						<input id="name" name="name" type="text" style="width: 150px" class="inputxt" datatype="*" nullmsg="请填写名字"/>
					</td>
				</tr>
				<tr>
					<td align="right" style="width: 100px;">
						<label class="Validform_label">手机1:</label>
					</td>
					<td class="value" style="width: 300px;">
				     	<input id="cellphone1" name="cellphone1" type="text" style="width: 150px" class="inputxt" datatype="cPhone"/>
					</td>
					<td align="right" style="width: 100px;">
						<label class="Validform_label">手机2:</label>
					</td>
					<td class="value" style="width: 300px;">
						<input id="cellphone2" name="cellphone2" type="text" style="width: 150px" class="inputxt"/> 
					</td>
				</tr>
				<tr>
					<td align="right" style="width: 100px;">
						<label class="Validform_label">固话:</label>
					</td>
					<td class="value" style="width: 300px;">
						<input id="telephone" name="telephone" type="text" style="width: 150px" class="inputxt" >    
					</td>
					<td align="right" style="width: 100px;">
						<label class="Validform_label">性别:</label>
					</td>
					<td class="value" style="width: 300px;">
						<t:dictSelect field="gender" type="select" typeGroupCode="<%=StaticValue.DIC_SEX %>" ></t:dictSelect>  
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							传真:
						</label>
					</td>
					<td class="value">
						<input id="fax" name="fax" type="text" style="width: 150px" class="inputxt" >
					</td>
					<td align="right">
						<label class="Validform_label">
							email:
						</label>
					</td>
					<td class="value">
					     <input id="email" name="email" type="text" style="width: 150px" class="inputxt" >
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							职位:
						</label>
					</td>
					<td class="value">
						<t:dictSelect field="position" id="position" type="select" typeGroupCode="<%=StaticValue.DIC_CONTACT_POSITION %>" hasPleaseSelect="false"></t:dictSelect>  
					</td>
					<td align="right">
						<label class="Validform_label">
							来源:
						</label>
					</td>
					<td class="value">
					      <input id="source" name="source" type="text" style="width: 150px" class="inputxt" >
					</td>
				</tr>
				<tr>
                    <td align="right">
                        <label class="Validform_label">
                            是否认证:
                        </label>
                    </td>
                    <td class="value">
                        <t:dictSelect field="authentication" id="authentication" type="select" typeGroupCode="trueOfFlaseNum" defaultVal="0"></t:dictSelect>
                    </td>

					<td align="right">
						<label class="Validform_label">
							状态:
						</label>
					</td>
					<td class="value">
						<t:dictSelect field="state" id="state" type="select" typeGroupCode="<%=StaticValue.DIC_ENGINEER_STATE %>" defaultVal="<%=StaticValue.DIC_ENGINEER_STATE_ONJOB %>"></t:dictSelect>
					</td>
				</tr>
            <tr>
                <td align="right">
                    <label class="Validform_label">
                        联系业务:
                    </label>
                </td>
                <td class="value" colspan="3">
                    <t:dictSelect field="conBusiness" type="checkbox" defaultVal="false" typeGroupCode="<%=StaticValue.DIC_LINK_BUSINESS %>" ></t:dictSelect>
                </td>
            </tr>
			</table>
		</t:formvalid>
</body>
<script src = "webpage/com/zybk/zy_contacts/zyContacts.js"></script>
<script type="text/javascript">
	function changeType() {
		var type= $("#type").val();
		if(type === '<%=StaticValue.DIC_CONTACT_TYPE_TP_CONTACT%>'){
			$("#org").show();
			$("#cinema").hide();
			$("#shortname").attr({"datatype":"*","nullmsg":"请选择所属机构"});
			$("#cinemaName").removeAttr("datatype nullmsg");
		}else if(type === '<%=StaticValue.DIC_CONTACT_TYPE_CINEMA_CONTACT%>'){
			$("#cinema").show();
			$("#org").hide();
			$("#cinemaName").attr({"datatype":"*","nullmsg":"请选择所属影院"});
			$("#shortname").removeAttr("datatype nullmsg");
		}else if(type === '<%=StaticValue.DIC_CONTACT_TYPE_WX_CONTACT%>'){
			$("#cinema").show();
			$("#org").hide();
			$("#cinemaName").attr({"datatype":"*","nullmsg":"请选择所属影院"});
			$("#shortname").removeAttr("datatype nullmsg");
		}
	}
</script>	